package com.fr.lintcode;

public class Q1353 {

    /**
     * @param root: the root of the tree
     * @return: the total sum of all root-to-leaf numbers
     */
	int count = 0;
    public int sumNumbers(TreeNode root) {
        // write your code here
    	if(root == null) {
    		return count;
    	}
    	search(0, root);
    	return count;
    }
	private void search(int pre, TreeNode root) {
		pre = pre * 10 + root.val;
		if(root.left == null && root.right == null) {
			count = count + pre;
			return;
		}
		if(root.left != null) {
			search(pre, root.left);
		}
		if(root.right != null) {
			search(pre, root.right);
		}
	}

}
